home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / dlldlg.com / DLLDIALG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-04-16  |  2.6 KB  |  77 lines

  1. { This code is hereby released to the Public Domain             }
  2. { by Dan Thomas  1991    Compuserve 72301,2164  Prodigy CWRF01A }
  3.  
  4. LIBRARY DllDialg;
  5. {**********************************************************************}
  6. {*    DllDialg  by Dan Thomas                                         *}
  7. {*                                                                    *}
  8. {*  Shows how to run a dialog from a DLL                              *}
  9. {**********************************************************************}
  10.  
  11. USES WinTypes, WObjects, WinProcs, Strings;
  12.  
  13. {$R DllDialg.res}
  14.  
  15. var
  16.   MsgText,
  17.   ResultText: string;
  18.   ResultSize: integer;
  19.   MyInstance: tHandle;
  20.  
  21.  
  22. {**********************************************************************}
  23. {*  Dialog procedure used by DialogBox                                *}
  24. {**********************************************************************}
  25. FUNCTION DllDialogProc(Dlg: hWnd; msg: word; wParam: word; lParam: longint): bool; export;
  26.  
  27. begin
  28.   DllDialogProc := false;
  29.   case msg of
  30.       wm_InitDialog : begin
  31.                         SetDlgItemText(Dlg,101,@MsgText[1]);
  32.                         SetDlgItemText(Dlg,102,@ResultText[1]);
  33.                         DllDialogProc := true;
  34.                       end;
  35.       wm_Command    : if wParam = id_OK then
  36.                         begin
  37.                           GetDlgItemText(Dlg,102,@ResultText[1],ResultSize);
  38.                           EndDialog(Dlg,1);
  39.                           DllDialogProc := true;
  40.                         end
  41.                       else
  42.                       if wParam = id_Cancel then
  43.                         begin
  44.                           EndDialog(Dlg,0);
  45.                           DllDialogProc := true;
  46.                         end;
  47.   end; {of case}
  48. end; {DllDialogProc}
  49.  
  50. {**********************************************************************}
  51. {*  Function that you call:                                           *}
  52. {**********************************************************************}
  53. FUNCTION DllDialog(aMsgText,aResultText: pChar; aResultSize: integer): word; export;
  54.  
  55. var
  56.   w      : word;
  57.   MyProc : tFarProc;
  58.  
  59. begin
  60.   DllDialog := 1;
  61.   MsgText := StrPas(aMsgText)+#00;
  62.   ResultText := StrPas(aResultText)+#00;
  63.   ResultSize := aResultSize;
  64.   MyProc := MakeProcInstance(@DllDialogProc,MyInstance);
  65.   w := DialogBox(MyInstance,'DLLDIALG',0,MyProc);
  66.   FreeProcInstance(MyProc);
  67.   if w = id_OK then
  68.     StrPCopy(aResultText,ResultText);
  69.   DllDialog := w;
  70. end; {DllDialog}
  71.  
  72. exports DllDialog index 1;
  73.  
  74. begin
  75.   MyInstance := system.hInstance;
  76. end.
  77.